<template>
	<view>

		<u-cell-group>
			<u-cell title="竞赛管理" isLink url="/competition/index"></u-cell>
			<u-cell title="社团管理" isLink url="/community/index"></u-cell>
		</u-cell-group>

		<u-modal :show="binding.idBind" :title="binding.title" :showConfirmButton="false">
			<view class="slot-content">
				<u-radio-group v-model="radiovalue1" placement="row" @change="groupChange">
					<u-radio :customStyle="{marginBottom: '8px'}" v-for="(item, index) in binding.userTypes"
						:key="index" :label="item.userType" :name="item.userType">
					</u-radio>
				</u-radio-group>
			</view>
		</u-modal>
		<u-modal :show="binding.isTeacher" :title="binding.bindTeacher" :showCancelButton="true"
			@confirm="confirmTeacher" @cancel="cancel">
			<view class="slot-content">
				<u-search placeholder="请输入你的姓名" v-model="teacherName" :showAction="false" @change="seachTeacherName"></u-search>
			</view>
		</u-modal>
		<u-modal :show="binding.isStudent" :title="binding.bindStudent" :showCancelButton="true"
			@confirm="confirmStudent" @cancel="cancel">
			<view class="slot-content">
				<u-search placeholder="请输入你的姓名" v-model="studentName" :showAction="false" @search="seachStudentName"></u-search>
				<view class="student-list">
					<u-list  v-for="(item,index) in students" :key="index" :height="150">
						<u-list-item>
							{{item.studentName}}
						</u-list-item>
					</u-list>
				</view>
			</view>
		</u-modal>
		<u-modal :show="binding.isAssitant" :title="binding.bindAssitant" :showCancelButton="true"
			@confirm="confirmAssistant" @cancel="cancel">
			<view class="slot-content">
				<u-search placeholder="请输入你的姓名" v-model="assistantName" :showAction="false" @change="seachAssistantName"></u-search>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				binding: {
					idBind: false,
					title: "绑定用户类型",
					content: "绑定",

					userTypes: [{
							id: 1,
							userType: '学生'
						},
						{
							id: 2,
							userType: '教师'
						},
						{
							id: 3,
							userType: '教辅'
						},
					],
					userType: '',
					bindStudent: '绑定学生',
					bindTeacher: '教师学生',
					bindAssitant: '教师学生',
					isTeacher: false,
					isStudent: false,
					isAssitant: false
				},
				teacherName: '',
				studentName: '',
				assistantName: '',
				students:[],
				teacher:[],
				

			}
		},
		computed: {
			...mapState(['$token', '$bingding'])
		},
		onLoad() {
			// #ifdef MP-WEIXIN
			this.binding.idBind = this.$bingding ? false : true;
			this.isLogin();
			// #endif
		},
		methods: {
			isLogin() {
				if (!this.$token) {
					uni.redirectTo({
						url: '/pages/index/login'
					})
				}


			},
			groupChange(n) {
				console.log(n);
				switch (n) {
					case '学生':
						this.binding.idBind = false
						this.binding.isStudent = true;
						this.binding.isTeacher = false;
						this.binding.isAssitant = false;
						break;
					case '教师':
						this.binding.idBind = false
						this.binding.isStudent = false;
						this.binding.isTeacher = true;
						this.binding.isAssitant = false;
						break;
					default:
						this.binding.idBind = false
						this.binding.isStudent = false;
						this.binding.isTeacher = false;
						this.binding.isAssitant = true;
						break;
				}
			},
			seachTeacherName(teacherName) {

			},
			async seachStudentName(studentName) {
				let res = await uni.$u.http.get('/api/student/name', {
						params: {
							studentName: studentName
						}
					}
				)
				console.log(res)
				if (res.success) {
					this.students=res.data.students;
				}
				else{
					
				}

			},
			seachAssistantName(assistantName) {


			},
			confirmAssistant() {

			},
			confirmStudent() {

			},
			confirmTeacher() {

			},
			cancel() {
				this.binding.idBind = true
				this.binding.isStudent = false;
				this.binding.isTeacher = false;
				this.binding.isAssitant = false;
			}



		}
	}
</script>

<style>
	
	.student-list{
		max-height:150px ;
	}

</style>
